<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<title>慢病评估</title>
<%@ include file="/commons/static.jsp"%>
<link rel="shortcut icon" href="${ctx }/dep/moban/img/favicon.png"
	type="image/x-icon">
<!--Basic Styles-->
<!--Beyond styles-->

<!---->
<link href="${ctx }/dep/moban/css/dataTables.bootstrap.css"
	rel="stylesheet" />
<link href="${ctx}/dep/layer/skin/layer.css" rel="stylesheet" />
<script src="${ctx}/dep/layer/layer.min.js"></script>
</head>
<body>
	<div class="wrapper">
		<div class="page-breadcrumbs">
			<ul class="breadcrumb">
				<li><i class="fa fa-home"></i> <a href="index.html">健康评估管理</a>
				</li>
				<li class="active"><a href="###">慢病评估</a></li>
			</ul>
		</div>
		<div class="page-body">
			<div class="row">

				<div class="col-xs-12 col-md-12">

					<div class="widget">
						<!--Widget Header-->
						<div class="widget-body">

							<div id="home" class="tab-pane in active">
								<div class="table-toolbar">

									<a href="javascript:void(0);" onclick="delAll()"
										class="btn btn-darkorange col-padd"> <i
										class="fa fa-minus"></i>批量删除
									</a> <a href="javascript:void(0)" 
										class="btn btn-success col-padd piliang"> <i
										class="fa fa-download"></i>批量下载
									</a>
									<form action="" id="hiddens"></form>
								</div>
								<table class="table table-striped table-hover table-bordered"
									id="bodyHtml">
									<thead>
										<tr role="row">
											<th width="5%"><label> <input type="checkbox"
													id="hvtck"> <span class="text" id="dohovertree"></span>

											</label></th>
											<th>编号 <span class="fa indicator fa-unsorted"></span>
											</th>
											<th>会员名称 <span class="fa indicator fa-unsorted"></span>
											</th>
											<th>慢病评估报告名称 <span class="fa indicator fa-unsorted"></span>
											</th>
											<th>慢病评估报告描述 <span class="fa indicator fa-unsorted"></span>
											</th>
											<th>评估时间 <span class="fa indicator fa-unsorted"></span>
											</th>
											<th width="20%">操作<span class="fa indicator fa-unsorted"></span>
											</th>
										</tr>
									</thead>

									<tbody>
										<c:forEach items="${pager.list }" var="list">
											<tr>
												<td><label> <input type="checkbox"
														data-customer="${list.customerName }"
														data-name="${list.assessmentName }"
														data-url="${list.assessmentUrl }" id="${list.id }"
														name="myHoverTreechk" /> <span class="text"></span>
												</label></td>
												<td><input type="text" class="six" value="${list.code }"
													disabled="disabled"></td>
												<td><input type="text" value="${list.customerName }"
													class="six" disabled="disabled"></td>
												<td><input type="text" class="six"
													value="${list.assessmentName }" disabled="disabled"></td>
												<td><input type="text" value="${list.description }"
													class="six" disabled="disabled"></td>
												<td><input type="text" class="six"
													value=" <fmt:formatDate value="${list.assessmentTime }" type='both'/>"
													disabled="disabled"></td>

												<td customerId="${list.customerId }" customerName = "${list.customerName }"><c:if
														test="${empty list.assessmentUrl}">
														<a href="${ctx }/assessment/auditPage/${list.id}"
															class="btn btn-primary btn-xs edit"><i
															class="fa fa-hdd-o"></i> 审核</a>
														<a href="javascript:void(0)"
															class="btn btn-ck btn-xs edit label-default "><i
															class="fa fa-folder-open-o"></i>查看</a>
														<a href="javascript:void(0)"
															class="btn btn-ck btn-xs label-default"><i
															class="fa fa-download"></i>下载</a>
													</c:if> <c:if test="${!empty list.assessmentUrl}">
														<a href="javascript:void(0)"
															class="btn btn-ck btn-xs edit label-default"><i
															class="fa fa-hdd-o"></i>审核</a>
														<a href="javascript:void(0)"
															class="btn btn-ck btn-xs edit viewPDF"
															pdfurl="${list.assessmentUrl }"><i
															class="fa fa-folder-open-o"></i>查看</a>
														<a
															href="javascript:downloadOneFile('${list.customerName==null?'null':list.customerName }', '${list.assessmentName==null?'null':list.assessmentName }', '${list.assessmentUrl }' )"
															class="btn btn-info btn-xs"><i class="fa fa-download"></i>下载</a>
													</c:if> <a href="#" class="btn btn-danger btn-xs removeClass"><i
														class="fa fa-trash-o"></i> 删除</a></td>

											</tr>
										</c:forEach>
									</tbody>
								</table>
								<%@ include file="../def/common_pagebar.jsp"%>
							</div>

						</div>
						<!--Widget Body-->
					</div>

				</div>

			</div>
		</div>
		<P class="bottomfont">© 2016 Angel Health Management Ltd. :
			天使健康管理有限公司</P>
	</div>
	<script>
		function downloadOneFile(customerName, assessmentName, assessmentUrl) {

			var name = assessmentName;

			if (assessmentName == '' || assessmentName == ""
					|| assessmentName == "null") {
				name = customerName + "的慢病评估报告"
			}

			location.href = ctx + "/downloadFile/download?fileName=" + name
					+ "&filePath=" + assessmentUrl;
		}

		//文件下载
		$(document).on('click','.piliang',function(){


			if ($('input[name="myHoverTreechk"]:checked').length <= 0) {
				toastr.warning('请至少选择一个文件进行下载');
				return;
			}

			var files = "";

			var status = 1;

			$('input[name="myHoverTreechk"]:checked').each(function() {

				var file = {};

				var url = $(this).data("url");

				if (url == null || url == "") {
					status = 0;
				}

				var name = $(this).data("name");
				var customerName = $(this).data("customer");

				if (name == null || name == "") {
					name = customerName + "的慢病评估报告";
				}

				file['url'] = url;
				file['name'] = name;

				files = files + JSON.stringify(file) + ",,";

			})

			if (status == 0) {
				toastr.warning('请选择可下载的文件');
				return;
			}

			files = files.substr(0, files.length - 2);

			location.href = ctx + "/downloadFile/downloadFiles?myFiles="
					+ files + "&zipName=慢病评估报告";
		})

		//批量删除
		function delAll() {
			var checkboxs = document.getElementsByName("myHove" + "rTreechk");
			cklen = checkboxs.length;
			var s = "";
			for (var i = 0; i < cklen; i++) {
				if (checkboxs[i].checked) {
					s = s + checkboxs[i].id + ","
				}
			}
			s = s.substring(0, s.length - 1);
			del(s);
		}

		function del(e) {
			$.ajax({
				type : "post",
				url : ctx + "/assessment/del",
				data : {
					"ids" : e
				},
				dataType : "json",
				success : function(data) {
					if (data > 0) {
						location.reload();
					} else {

					}
				}
			});
		}
		$(function() {
			
			$(document).on('click', '.pinggu', function(){
				/* 直接声称的代码 
				var customerId = $(this).parent().attr("customerId");
				var customerName = $(this).parent().attr("customerName");
				var th = $(this);
				$(th).html("<i class='fa fa-hdd-o'></i>生成中");
				$(th).attr("class","btn btn-ck btn-xs edit label-default");
				$.ajax({
					type:"POST",
					url:ctx +'/healthReport/generate',
					data:{
						customerId:customerId
					},
					dataType: "json",
					success:function(data){
						if(data){
							
							$(th).next().attr("class","btn btn-ck btn-xs edit viewPDF").attr("pdfurl",data);
							$(th).next().next().attr("class","btn btn-info btn-xs").attr("href","javascript:downloadOneFile('"+customerName+"', 'null', '"+data +"')");
							$(th).parent().parent().find("input[name='myHoverTreechk']").attr("data-url",data);
							$(th).html("<i class='fa fa-hdd-o'></i>评估");
							layer.open({
								type : 2,
								title : [ 'PDF 查看', 'background: #f3f3f3;color:##737373' ],
								shadeClose : true,
								shade : 0.6,
								area : [ '1200px', '100%' ],
								content : data
							});
						}else{
							toastr.warning('生成失败');
						}
					}
				}); */
			});

			$(".removeClass").on(
					'click',
					function() {
						var id = $(this).parent().parent().find(
								"input[name='myHoverTreechk']").attr("id");
						del(id);
					});
			
			$(document).on('click', '.viewPDF', function(){
				var pdfurl = $(this).attr("pdfurl");
				layer.open({
					type : 2,
					title : [ 'PDF 查看', 'background: #f3f3f3;color:##737373' ],
					shadeClose : false,
					shade : 0.6,
					area : [ '1200px', '100%' ],
					content : pdfurl
				});
			})
		});

		window.onload = function() {
			var checkboxs = document.getElementsByName("myHove" + "rTreechk");
			var hvtck = document.getElementById("hvtck");
			cklen = checkboxs.length;
			hvtck.onclick = function() {
				if (this.checked == true) {
					for (var i = 0; i < cklen; i++) {
						checkboxs[i].checked = true;
					}
					document.getElementById("dohovert" + "ree").innerHTML = ""
				} else {
					for (var i = 0; i < cklen; i++) {
						checkboxs[i].checked = false;
					}
					document.getElementById("dohovertree").innerHTML = ""
				}
			}
		}
	</script>

</body>
</html>
